package com.blog.controller;

        import com.blog.common.ServerResponse;
        import com.blog.exception.MyException;
        import com.blog.pojo.Category;
        import com.blog.pojo.User;
        import com.blog.service.ICategoryService;
        import com.blog.service.IUserService;
        import org.apache.log4j.Logger;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.stereotype.Controller;
        import org.springframework.ui.ModelMap;
        import org.springframework.util.StringUtils;
        import org.springframework.web.bind.annotation.RequestMapping;
        import org.springframework.web.bind.annotation.RequestMethod;
        import org.springframework.web.bind.annotation.RequestParam;
        import org.springframework.web.bind.annotation.ResponseBody;

        import javax.servlet.http.HttpServletRequest;
        import java.util.List;


/**
 * @author
 * @create 2018-06-04 15:09
 **/
@Controller
@RequestMapping("/category/")
public class CategoryController {

    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private ICategoryService iCategoryService;

    /**
     * 查询所有
     *
     * @param map
     * @return
     */
    @RequestMapping("list.action" )
    public String list(ModelMap map) {

        List<Category> list = iCategoryService.list();
        map.put("list", list);
        return "admin/category/list";
    }


    /**
     * 更新或插入
     *
     * @param
     * @return
     */
    @RequestMapping(value = "save.json")
    @ResponseBody
    public ServerResponse save( @RequestParam(value = "idArr") String[] idArr, @RequestParam(value = "soreArr") String[] soreArr, @RequestParam(value = "nameArr") String[] nameArr) {
     return iCategoryService.save(idArr, soreArr, nameArr);
    }

    @RequestMapping(value = "delete.json")
    @ResponseBody
    public ServerResponse deleteById( @RequestParam(value = "idArr") String[] idArr) {
        return iCategoryService.deleteById(idArr);
    }

    public static void main(String[] args) {
        System.out.println("你好");
    }
}
